<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\common\model;

use think\Model;


class UserFollow extends Model
{

    

    const CANCEL_YES = 1;
    const CANCEL_NO = 0;
    const MUTUAL_YES = 1;
    const MUTUAL_NO = 0;

    // 表名
    protected $name = 'user_follow';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'mutual_text',
        'cancel_text',
        'create_time_text',
        'update_time_text'
    ];
    

    
    public function getMutualList()
    {
        return ['0' => __('Mutual 0'), '1' => __('Mutual 1')];
    }

    public function getCancelList()
    {
        return ['0' => __('Cancel 0'), '1' => __('Cancel 1')];
    }


    public function getMutualTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['mutual']) ? $data['mutual'] : '');
        $list = $this->getMutualList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCancelTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['cancel']) ? $data['cancel'] : '');
        $list = $this->getCancelList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCreateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getUpdateTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCreateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setUpdateTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
